import java.io.*;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) {
        Long time = System.currentTimeMillis();
        File javaFile = new File("D:\\workspace\\myAPI\\src\\main\\java\\com\\myAPI\\controller\\MainController.java");
        try {
            BufferedReader br = new BufferedReader(new FileReader(javaFile));
            String line;
            Integer singleAnnonation = 0;
            Integer multiAnnonation = 0;
            Boolean isMulti = false;
            while ((line = br.readLine()) != null) {
                //System.out.println(line);
                // 把代码前后多余空格都去掉
                line = line.trim();
                if (isMulti) {
                    if (line.contains("*/")) {
                        isMulti = false;
                        multiAnnonation += 1;
                    } else {
                        continue;
                    }
                } else {
                    if(line.startsWith("//")) {
                        // 如果开头就是注释符，就直接判断
                        singleAnnonation += 1;
                    } else if (line.startsWith("/*")) {
                        isMulti = true;
                        continue;
                    } else if (true) {
                        // 可能的形式
                        // String abc = "abced// dedb"
                        // xxxxxxx.aaaaa("abced// dedb", xxxxxbbbb)
                        // "xxxxxx".replaceAll();
                        // String a = "xxxxxx"; String b = "cccccccc";
                        //line.replaceAll("^\"*\"$", "aaaa");
                        Pattern regex = Pattern.compile("\"(.*)\"");   // 也可以用正则断言，取到两者中间的。
                        Matcher matcher = regex.matcher(line);
                        Pattern regex2 = Pattern.compile("\"(.*?)\"");   // 也可以用正则断言，取到两者中间的。
                        Matcher matcher2 = regex2.matcher(line);
                        if (matcher.find() && matcher2.find()) {
                            if ((matcher.group()).equals(matcher2.group())) {
                                // 如果非贪婪与贪婪一致，表明就是一个纯字符串
//                                continue;
                            } else {
                                System.out.println("jjjjjjjjjjjj");
                                System.out.println(matcher.group());
                                System.out.println(matcher2.group());
                                // 查询第一个字符串结束位置
                                int end = line.indexOf("\"", 1);
                                // 判断该字符串是不是转义的。
                                String temp = line.substring(0, end + 1);
                                Pattern regex3 = Pattern.compile("\\*\"$");
                                Matcher matcher3 = regex3.matcher(temp);
                                System.out.println("ppppppppppppppppppppp");
                                if (matcher3.find()) {
                                    System.out.println(matcher3.group());
                                }

                            }
                        }

                    }
                }

               // System.out.println(line.trim());
            }
            // 没有老式的循环快，慢一个数量级
//            br.lines().forEach(action -> {
//                System.out.println(action);
//            });

//            if (br.lines()) {
//
//            }
            System.out.println("abcccceeee".replaceAll("cc\\///adfa", "!"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        Long time2 = System.currentTimeMillis();
        System.out.println((time2 - time)/1);
    }
}
